package com.sysu.simulation.widget;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.sysu.simulation.R;


public class SimStageCard extends FrameLayout implements View.OnClickListener{
    private ImageView closeButton;
    private Button slowSpeed;
    private Button midSpeed;
    private Button fastSpeed;
    private EditText mSpeed;
    private EditText mDuration;
    private TextView mNumber;
    private OnCloseCardListener mListener;

    public SimStageCard(@NonNull Context context) {
        super(context);
        init();
    }

    public SimStageCard(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SimStageCard(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public SimStageCard(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        inflater.inflate(R.layout.item_sim_stage, this, true);

        closeButton = (ImageView) findViewById(R.id.sim_stage_close);
        slowSpeed = (Button) findViewById(R.id.sim_stage_slow);
        midSpeed = (Button) findViewById(R.id.sim_stage_mid);
        fastSpeed = (Button) findViewById(R.id.sim_stage_fast);
        mSpeed = (EditText) findViewById(R.id.sim_speed);
        mDuration = (EditText) findViewById(R.id.sim_duration);
        mNumber = (TextView) findViewById(R.id.sim_stage_number);

        closeButton.setOnClickListener(this);
    }

    public String getSpeed() {
        return mSpeed.getText().toString().trim();
    }

    public String getDuration() {
        return mDuration.getText().toString().trim();
    }

    public EditText getEditSpeed() {
        return mSpeed;
    }

    public EditText getEditDuration() {
        return mDuration;
    }

    public void setNumber(int number) {
        mNumber.setText(String.valueOf(number));
    }

    public int getNumber() {
        return Integer.parseInt(mNumber.getText().toString());
    }

    @Override
    public void onClick(View view) {
        mListener.onCloseCard(getNumber());
    }

    public void setOnCloseCardListener(OnCloseCardListener l) {
        mListener = l;
    }

    public interface OnCloseCardListener {
        void onCloseCard(int number);
    }
}
